<template>
  <el-dialog :visible.sync="dialogVisible" width="500px" title="下载提醒" center
             :close-on-click-modal="false" :close-on-press-escape='false'>
    <div class="content">
      <p>本次扣除：{{row.del}} <span>剩余条数：{{row.rest}}</span></p>
    </div>
    <div slot="footer" class="dialog-footer" align="right">
      <el-button @click="dialogVisible = false" size="mini">取 消</el-button>
      <el-button type="primary" @click="down" size="mini">继续下载
      </el-button>
    </div>
  </el-dialog>
</template>

<script>
    import {downLoadAll} from '@/api/automation/customs'
    import website from '@/config/website';

    export default {
        name: "DialogDownload",
        data() {
            return {
                dialogVisible: false,
                row: {},
            }
        },
        methods: {
            init(row) {
                this.row = row;
                this.dialogVisible = true;
            },
            down() {
                const param = {
                    basename: this.row.basename,
                    ids: this.row.ids,
                    page: this.row.page,
                    n: this.row.n,
                    count: this.row.rest
                }
                this.dialogVisible = false;
                downLoadAll(param).then(res => {
                    const result = res.data.data;
                    if (res.data.success&&result.indexOf(".xlsx")!=-1) {
                        window.open(website.hg_URL + result, '_blank');
                    }else{
                        this.$message({
                            message: '数据下载未成功!',
                            type: "success"
                        });
                    }
                })
            }
        }
    }
</script>

<style scoped lang="scss">
  .content {
    margin: 30px 0;
    p {
      color: #232323;
      font-size: 16px;
      padding: 10px 15px;
      text-align: center;
      span{
        margin-left: 70px;
      }
    }
  }
</style>
